import "reflect-metadata"
import Editor from "./editor"
import "./input.css"

import { undoRedoPlugin, logPlugin } from "./plugins"

window.onload = () => {
  const container = document.getElementById("container-pre")
  if (container) {
    const editor = new Editor(
      container,
      [logPlugin, undoRedoPlugin],
      "source_preview",
    )
    editor.init()
    const clear = document.getElementById("clear")
    if (clear) {
      clear.onclick = () => {
        editor.clearPlugins()
      }
    }

    const preview = document.getElementById("preview")
    if (preview) {
      preview.onclick = () => {
        editor.setMode("source_preview")
      }
    }

    const source = document.getElementById("source")
    if (source) {
      source.onclick = () => {
        editor.setMode("source")
      }
    }
  }
}
